package com.cheng.gmall.product;


import com.cheng.gmall.product.entity.SkuImage;
import com.cheng.gmall.product.mapper.SkuImageMapper;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package com.cheng.gmall.product
 * @date 2024/5/29 下午3:39
 */

@SpringBootTest
public class RWTtest {
    @Autowired
    SkuImageMapper skuImageMapper;

@Test
void testshiwu(){
    //先修改再读取
    SkuImage skuImage = new SkuImage();
    skuImage.setId(263L);
    skuImage.setSkuId(1L);
    skuImage.setImgName("bbbb");
    skuImage.setImgUrl("aaa～～～～");
    skuImage.setSpuImgId(1L);
    skuImage.setIsDefault("1");

    skuImageMapper.updateById(skuImage);
    System.out.println("修改完成");
//读取;上次修改的同一个数据，下次读不要去从库，因为从库可能没有同步到
    //强制从主库读取

    HintManager.getInstance().setWriteRouteOnly();//设置仅主库路由
    SkuImage skuImage1 = skuImageMapper.selectById(263L);
    System.out.println("skuImage1 = " + skuImage1);
}


    @Test
    void testread(){
        SkuImage skuImage = skuImageMapper.selectById(263);
        SkuImage skuImage2 = skuImageMapper.selectById(263);
        SkuImage skuImage23 = skuImageMapper.selectById(263);
        SkuImage skuImage3 = skuImageMapper.selectById(263);

    }
    @Test
    void testtrw(){

        SkuImage skuImage = new SkuImage();

        skuImage.setSkuId(1L);
        skuImage.setImgName("aaa");
        skuImage.setImgUrl("aaa");
        skuImage.setSpuImgId(1L);
        skuImage.setIsDefault("1");

        skuImageMapper.insert(skuImage);
    }
}
